//
//  KDMBaseTableViewController.m
//  KouDaiMaster
//
//  Created by 范智渊 on 2018/4/18.
//  Copyright © 2018年 zzgk. All rights reserved.
//

#import "KDMBaseTableViewController.h"

@interface KDMBaseTableViewController ()
@property (nonatomic, strong) MJRefreshBackNormalFooter *footer;

@end

@implementation KDMBaseTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void) addRefreshController
{

    WeakSelf;
    //1.创建下拉刷新控件loadNewDeals
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf loadNewData];
        [weakSelf.tableView.mj_header endRefreshing];

    }];
    header.lastUpdatedTimeLabel.hidden = YES;

    [header setTitle:@"" forState:MJRefreshStatePulling];

    [header setTitle:@"" forState:MJRefreshStateIdle];
    [header setTitle:@"" forState:MJRefreshStateRefreshing];
    self.tableView.mj_header = header;
    // 设置回调（一旦进入刷新状态就会调用这个refreshingBlock）
    [self.tableView.mj_header beginRefreshing];//执行之后会调用loadNewDeals方法
    header.lastUpdatedTimeKey = MJRefreshHeaderLastUpdatedTimeKey;

    //2.设置上拉加载
    _footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        [weakSelf loadMoreDatas];
        [self.tableView.mj_header endRefreshing];
    }];
    [_footer setTitle:@"" forState:(MJRefreshStatePulling)];
    [_footer setTitle:@"" forState:(MJRefreshStateIdle)];
    [_footer setTitle:@"" forState:(MJRefreshStateRefreshing)];
    //没有数据加载是自动隐藏

    //    footer.automaticallyHidden = YES;
    self.tableView.mj_footer = _footer;
    self.tableView.mj_header.automaticallyChangeAlpha = YES;

}

#pragma mark - 和服务器相关的方法
//上拉加载
- (void) loadMoreDatas
{
    self.page++;
    if(!self.lastPage) {
        [self setRequestToServerWithPage:self.page];
    } else{
        [_footer setTitle:@"没有更多数据" forState:(MJRefreshStatePulling)];
        //        [_footer setTitle:@"我要获取更多数据" forState:(MJRefreshStateIdle)];
        //        [_footer setTitle:@"正在加载更多数据 ..." forState:(MJRefreshStateRefreshing)];
    }
}
//下拉刷新
- (void) loadNewData
{
    self.page = 1;
    [self setRequestToServerWithPage:self.page];

}
- (void)settingParams:(NSDictionary *)paramsDict WithClass:(Class)subClass
{


}

- (void)setRequestToServerWithPage:(int)page
{


}




@end
